home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / libwww2 / HTFormat.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  9.6 KB  |  344 lines

  1. /*                                            HTFormat: The format manager in the WWW Library
  2.                             MANAGE DIFFERENT DOCUMENT FORMATS
  3.                                              
  4.    Here we describe the functions of the HTFormat module which handles conversion between
  5.    different data representations.  (In MIME parlance, a representation is known as a
  6.    content-type. In WWW  the term "format" is often used as it is shorter).
  7.    
  8.    This module is implemented by HTFormat.c . This hypertext document is used to generate
  9.    the HTFormat.h inlude file.  Part of the WWW library.
  10.    
  11. Preamble
  12.  
  13.  */
  14. #ifndef HTFORMAT_H
  15. #define HTFORMAT_H
  16.  
  17. #include "HTUtils.h"
  18. #include "HTStream.h"
  19. #include "HTAtom.h"
  20. #include "HTList.h"
  21.  
  22. #ifdef SHORT_NAMES
  23. #define HTOutputSource HTOuSour
  24. #define HTOutputBinary HTOuBina
  25. #endif
  26.  
  27. /*
  28.  
  29. The HTFormat type
  30.  
  31.    We use the HTAtom object for holding representations. This allows faster manipulation
  32.    (comparison and copying) that if we stayed with strings.
  33.    
  34.  */
  35. typedef HTAtom * HTFormat;
  36.                         
  37. /*
  38.  
  39.    These macros (which used to be constants) define some basic internally referenced
  40.    representations.  The www/xxx ones are of course not MIME standard.
  41.    
  42.    www/source  is an output format which leaves the input untouched. It is useful for
  43.    diagnostics, and for users who want to see the original, whatever it is.
  44.    
  45.  */
  46.                         /* Internal ones */
  47. #define WWW_SOURCE HTAtom_for("www/source")     /* Whatever it was originally*/
  48.  
  49. /*
  50.  
  51.    www/present represents the user's perception of the document.  If you convert to
  52.    www/present, you present the material to the user.
  53.    
  54.  */
  55. #define WWW_PRESENT HTAtom_for("www/present")   /* The user's perception */
  56.  
  57. /*
  58.  
  59.    The message/rfc822 format means a MIME message or a plain text message with no MIME
  60.    header. This is what is returned by an HTTP server.
  61.    
  62.  */
  63. #define WWW_MIME HTAtom_for("www/mime")         /* A MIME message */
  64. /*
  65.  
  66.    www/print is like www/present except it represents a printed copy.
  67.    
  68.  */
  69. #define WWW_PRINT HTAtom_for("www/print")       /* A printed copy */
  70.  
  71. #define WWW_PLAINTEXT   HTAtom_for("text/plain")
  72. #define WWW_POSTSCRIPT  HTAtom_for("application/postscript")
  73. #define WWW_RICHTEXT    HTAtom_for("application/x-rtf")
  74. #define WWW_HTML        HTAtom_for("text/html")
  75. #define WWW_BINARY      HTAtom_for("application/octet-stream")
  76.  
  77. /*
  78.  
  79.    We must include the following file after defining HTFormat, to which it makes
  80.    reference.
  81.    
  82.    The HTEncoding type
  83.    
  84.    typedef HTAtom* HTEncoding;
  85.    
  86.    The following are values for the MIME types:
  87.    
  88.    #define WWW_ENC_7BIT
  89.    
  90.    #define WWW_ENC_8BIT
  91.    
  92.    #define WWW_ENC_BINARY
  93.    
  94.    We also add
  95.    
  96.  */
  97. #include "HTAnchor.h"
  98.  
  99. /*
  100.  
  101. The HTPresentation and HTConverter types
  102.  
  103.    This HTPresentation structure represents a possible conversion
  104.    algorithm from one format to annother.  It includes a pointer to a
  105.    conversion routine. The conversion routine returns a stream to
  106.    which data should be fed. See also HTStreamStack which scans the
  107.    list of registered converters and calls one. See the initialisation
  108.    module for a list of conversion routines.
  109.    
  110.  */
  111. typedef struct _HTPresentation HTPresentation;
  112.  
  113. typedef HTStream * HTConverter PARAMS((
  114.         HTPresentation *        pres,
  115.         HTParentAnchor *        anchor,
  116.         HTStream *              sink,
  117.         HTFormat                format_in,
  118.         int                     compressed));
  119.         
  120. struct _HTPresentation {
  121.         HTAtom* rep;            /* representation name atmoized */
  122.         HTAtom* rep_out;        /* resulting representation */
  123.         HTConverter *converter; /* The routine to gen the stream stack */
  124.         char *  command;        /* MIME-format string */
  125.         float   quality;        /* Between 0 (bad) and 1 (good) */
  126.         float   secs;
  127.         float   secs_per_byte;
  128. };
  129.  
  130. /*
  131.  
  132.    The list of presentations is kept by this module.  It is also scanned by modules which
  133.    want to know the set of formats supported. for example.
  134.    
  135.  */
  136. extern HTList * HTPresentations;
  137.  
  138. /*
  139.  
  140. HTSetPresentation: Register a system command to present a format
  141.  
  142.   ON ENTRY,
  143.   
  144.   rep                     is the MIME - style format name
  145.                          
  146.   command                 is the MAILCAP - style command template
  147.                          
  148.   quality                 A degradation faction 0..1
  149.                          
  150.   maxbytes                A limit on the length acceptable as input (0 infinite)
  151.                          
  152.   maxsecs                 A limit on the time user will wait (0 for infinity)
  153.                          
  154.  */
  155. extern void HTSetPresentation PARAMS((
  156.         CONST char * representation,
  157.         CONST char * command,
  158.         float   quality,
  159.         float   secs,
  160.         float   secs_per_byte
  161. ));
  162.  
  163.  
  164. /*
  165.  
  166. HTSetConversion:   Register a converstion routine
  167.  
  168.   ON ENTRY,
  169.   
  170.   rep_in                  is the content-type input
  171.                          
  172.   rep_out                 is the resulting content-type
  173.                          
  174.   converter               is the routine to make the stream to do it
  175.                          
  176.  */
  177.  
  178. extern void HTSetConversion PARAMS((
  179.         CONST char *    rep_in,
  180.         CONST char *    rep_out,
  181.         HTConverter *   converter,
  182.         float           quality,
  183.         float           secs,
  184.         float           secs_per_byte
  185. ));
  186.  
  187.  
  188. /*
  189.  
  190. HTStreamStack:   Create a stack of streams
  191.  
  192.    This is the routine which actually sets up the conversion. It
  193.    currently checks only for direct conversions, but multi-stage
  194.    conversions are forseen. It takes a stream into which the output
  195.    should be sent in the final format, builds the conversion stack,
  196.    and returns a stream into which the data in the input format should
  197.    be fed.  The anchor is passed because hypertxet objects load
  198.    information into the anchor object which represents them.
  199.    
  200.  */
  201. extern HTStream * HTStreamStack PARAMS((
  202.         HTFormat                format_in,
  203.         HTFormat                format_out,
  204.         int                     compressed,
  205.         HTStream*               stream_out,
  206.         HTParentAnchor*         anchor));
  207.  
  208. /*
  209.  
  210. HTStackValue: Find the cost of a filter stack
  211.  
  212.    Must return the cost of the same stack which HTStreamStack would set up.
  213.    
  214.   ON ENTRY,
  215.   
  216.   format_in               The fomat of the data to be converted
  217.                          
  218.   format_out              The format required
  219.                          
  220.   initial_value           The intrinsic "value" of the data before conversion on a scale
  221.                          from 0 to 1
  222.                          
  223.   length                  The number of bytes expected in the input format
  224.                          
  225.  */
  226. extern float HTStackValue PARAMS((
  227.         HTFormat                format_in,
  228.         HTFormat                rep_out,
  229.         float                   initial_value,
  230.         long int                length));
  231.  
  232. #define NO_VALUE_FOUND  -1e20           /* returned if none found */
  233.  
  234. /*
  235.  
  236. HTCopy:  Copy a socket to a stream
  237.  
  238.    This is used by the protocol engines to send data down a stream,
  239.    typically one which has been generated by HTStreamStack.
  240.    
  241.  */
  242. extern int HTCopy PARAMS((
  243.         int                     file_number,
  244.         HTStream*               sink,
  245.         int                     bytes_already_read));
  246.  
  247.         
  248. /*
  249.  
  250. HTFileCopy:  Copy a file to a stream
  251.  
  252.    This is used by the protocol engines to send data down a stream,
  253.    typically one which has been generated by HTStreamStack. It is
  254.    currently called by HTParseFile
  255.    
  256.  */
  257. extern void HTFileCopy PARAMS((
  258.         FILE*                   fp,
  259.         HTStream*               sink));
  260. #if 0
  261. extern void HTFileCopyToText PARAMS((
  262.         FILE*                   fp,
  263.         HText*                  text));
  264. #endif
  265.         
  266. /*
  267.  
  268. Clear input buffer and set file number
  269.  
  270.    This routine and the one below provide simple character input from sockets. (They are
  271.    left over from the older architecure and may not be used very much.)  The existence of
  272.    a common routine and buffer saves memory space in small implementations.
  273.    
  274.  */
  275. extern void HTInitInput PARAMS((int file_number));
  276.  
  277. /*
  278.  
  279. Get next character from buffer
  280.  
  281.  */
  282. extern char HTGetCharacter NOPARAMS;
  283.  
  284.  
  285. /*
  286.  
  287. HTParseSocket: Parse a socket given its format
  288.  
  289.    This routine is called by protocol modules to load an object.  uses
  290.    HTStreamStack and the copy routines above.  Returns HT_LOADED if
  291.    succesful, <0 if not.
  292.    
  293.  */
  294. extern int HTParseSocket PARAMS((
  295.         HTFormat        format_in,
  296.         HTFormat        format_out,
  297.         HTParentAnchor  *anchor,
  298.         int             file_number,
  299.         HTStream*       sink,
  300.         int             compressed));
  301.  
  302. /*
  303.  
  304. HTParseFile: Parse a File through a file pointer
  305.  
  306.    This routine is called by protocols modules to load an object. uses
  307.    HTStreamStack and HTFileCopy .  Returns HT_LOADED if succesful, <0
  308.    if not.
  309.    
  310.  */
  311. extern int HTParseFile PARAMS((
  312.         HTFormat        format_in,
  313.         HTFormat        format_out,
  314.         HTParentAnchor  *anchor,
  315.         FILE            *fp,
  316.         HTStream*       sink,
  317.         int             compressed));
  318.  
  319. /*
  320.  
  321. HTFormatInit: Set up default presentations and conversions
  322.  
  323.    These are defined in HTInit.c or HTSInit.c if these have been
  324. replaced. If you don't call this routine, and you don't define any
  325. presentations, then this routine will automatically be called the
  326. first time a conversion is needed. However, if you explicitly add some
  327. conversions (eg using HTLoadRules) then you may want also to
  328. explicitly call this to get the defaults as well.
  329.  
  330. */
  331. extern void HTFormatInit NOPARAMS;
  332.  
  333. /*
  334.  
  335. Epilogue
  336.  
  337.  */
  338. extern BOOL HTOutputSource;     /* Flag: shortcut parser */
  339. #endif
  340.  
  341. /*
  342.  
  343.    end  */
  344.